home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-05
/
1118.zip
/
1118.TXT
next >
Wrap
Text File
|
1993-03-08
|
5KB
|
131 lines
FYI
(Note: The origin of this information may be internal or external to Novell.
Novell makes every effort within its means to verify this information.
However, the information provided in this document is FOR YOUR INFORMATION
only. Novell makes no explicit or implied claims as to the validity of this
information.)
TITLE: BATCH PROGRAMMING
DOCUMENT ID#: FYI-M-1118
DATE: 10FEB93
PRODUCT: DR DOS
PRODUCT VERSION: 6.0
SUPERSEDES: 13OCT92
SYMPTOM: WRITING A BATCH PROGRAM THAT CAN EXECUTE MULTIPLE TIMES &
PERFORM IT'S DEFINED TASK ONLY ONCE
ISSUE/PROBLEM: Batch programming capabilities were recently changed. These
changes became effective with COMMAND.COM files dated after 4/7/92. The latest
COMMAND.COM is available via CompuServe or the Novell DSG Host BBS at
408-649-3443.
SOLUTION: This document contains a sample batch file that makes use of
the changes contained in the updated COMMAND.COM. This sample file
demonstrates the creation of a batch program that can be executed a number of
times but will perform the defined task only once a day.
1. Create a file called DTFRCMP.TXT that contains the current
date information by typing the following from the command
line: C:\>DATE >DTFRCMP.TXT
Press the Enter key twice to be returned to the prompt.
2. Create a file called CR using the EDITOR (EDITOR.EXE).
This file will contain a carriage return. To create this file:
a. Type EDITOR CR at the command prompt
b. When prompted, "do you wish to create a new file?"
Type Y.
c. You will then be in the EDITOR. Enter a carriage return
by pressing the ENTER key once.
d. Save the file by holding the CTRL key down and then
typing KX.
3. Create the main batch file that performs the daily routine.
a. From the command prompt (C:\>) type: EDITOR TEST.BAT
b. When prompted, "do you wish to create a new file?"
Type Y.
c. Proceed to type the following lines (creating the file):
@ECHO OFF
REM This logs the date information into a file.
DATE <CR >INF.TXT
REM This compares the preexisting date information
REM with the date information that was just created.
REM It creates a file with this information.
COMP INF.TXT DTFRCMP.TXT >CMP.RZT
REM This looks for the word "failure" in the created
REM text file. (This would be an indication that the
REM files are the same if "failure" was not found)...
REM Thus telling us that this batch file has already
REM been run today.
REM It pipes the results into a file.
FIND "FAILURE" CMP.RZT >DECIDER.TXT
REM If "failure" was found, then the file that was
REM created will have a file size. If it was not
REM found then it will have a zero byte file size.
REM This will try to copy the file to another file.
REM If the original file is a zero byte file then
REM this procedure will fail because the COPY
REM command cannot copy a zero byte file.
COPY DECIDER.TXT FINAL.TXT >NUL
REM This checks to see if the final file was created.
REM If it was not, then the daily routine will be
REM bypassed...this batch file has already been run today.
IF NOT EXIST FINAL.TXT GOTO FINAL
REM If this section has been reached, then the batch
REM file has not been run today and it is going to
REM execute the once-a-day command that it is intended
REM to execute. This can be any command of your choosing
REM as long as it works from the DOS prompt. The one that
REM has been chosen here is a command that copies the
REM config.sys file to a filename called ITWORKED.SYS.
:COPY
COPY C:\CONFIG.SYS C:\ITWORKED.SYS >NUL
ECHO Executing once-a-day routine...
REM This creates a new date-comparison file so that the
REM next time that this batch file is run it will see
REM that it has already been run today.
COPY INF.TXT DTFRCMP.TXT >NUL
REM This deletes the final comparison file that was created
REM today.
DEL FINAL.TXT
REM This cleans up all of the extra files and exits.
:END
DEL INF.TXT
DEL CMP.RZT
DEL DECIDER.TXT
EXIT
REM This tells you that it has already been run today.
:FINAL
echo Daily routine has already been run today.
GOTO END
If TEST.BAT is executed many times daily, it will create
the file ITWORKED.SYS just once a day.
NOTE: If you attempt to run this batch file on the same day that it
was created a message will be returned that this routine has already been run
today. This is because the information in the DTFRCMP.TXT file is the same as
the current day's date. If you wish to test it on the same day that the file
was created, you will have to change the date using the date command.
This file can be incorporated in the AUTOEXEC.BAT file to execute every time
the computer is turned on. To do this, use the EDITOR and add the following
line just before the line :DRDOSEND:
CALL TEST.BAT
Some possible uses of such a batch file would be running a daily virus scan,
system diagnostics or the disk optimizer.